
import java.io.File;

import org.apache.log4j.Logger;

import com.github.cdisk.xtrans.core.ConfigFile;
import com.github.cdisk.xtrans.core.GlobalVariables;

public class Main {

	private static final Logger LOGGER = Logger.getLogger(Main.class);

	public static com.github.cdisk.xtrans.core.Main main = null;

	public static void main(String[] args) throws Exception {
		System.out.println("[[========================================]]");
		System.out.println("[[=========== XTransport 1.2.1 ===========]]");
		System.out.println("[[========================================]]");
		LOGGER.info("检查日志目录.....");
		File file = new File(System.getProperty("user.dir") + "/logs/");
		if (!file.exists()) file.mkdirs();
		LOGGER.info("准备读取配置.....");
		try {
			String configFile = null; // 数据抽取流程转换文件（xdt）
			String variablesFile = null; // 全局变量配置文件（xml）
			if (args != null && args.length > 0) {
				configFile = args[0];
				configFile = configFile.replace("\"", "").replace("'", "");
				LOGGER.info("转换文件：" + configFile);
			} else {
//				LOGGER.error("no config file args, please use following command: java -jar xtrans.jar xxx.xdt");
//				return;
				configFile = "data.xdt";
				LOGGER.info("转换文件：" + configFile);
			}
			if (args.length > 1) {
				variablesFile = args[1];
				variablesFile = variablesFile.replace("\"", "").replace("'", "");
				LOGGER.info("全局变量文件：" + variablesFile);
			}

			GlobalVariables variables = new GlobalVariables(variablesFile);
			ConfigFile config = ConfigFile.Read(configFile, variables, true);
			LOGGER.info("配置文件读取完成.....");
			main = new com.github.cdisk.xtrans.core.Main(config);
			main.start();
		} catch (Exception e) {
			LOGGER.error(e, e);
			throw e;
		}
	}

}
